"use strict";

var React = require("react");
var Router = require("react-router");
var Link = Router.Link;

var AuthorList = React.createClass({
    propTypes: {
        authors: React.PropTypes.array.isRequired,
        deleteAuthor: React.PropTypes.func.isRequired
    },


    render: function () {
        var createAuthorRow = function (author) {
            return (
                <tr key={author.id}>
                    <td><Link to="manageAuthor" params={{id: author.id}}>{author.id}</Link></td>
                    <td>{author.firstName} {author.lastName}</td>
                    <td><a href="#" className="btn btn-danger" onClick={this.props.deleteAuthor.bind(this, author.id)}
                    >del</a></td>
                </tr>
            );
        };

        return (
            <div>
                <table className="table table-bordered">
                    <thead>
                    <th>Id</th>
                    <th>Name</th>
                    <th>del</th>
                    </thead>
                    <tbody>
                    {this.props.authors.map(createAuthorRow, this)}
                    </tbody>
                </table>
            </div>
        );
    }
});

module.exports = AuthorList;